package com.sinosoft.sinopay.web.batch.dto;

import com.sinosoft.sinocloud.platform.common.util.StringUtil;
import com.sinosoft.sinopay.web.batch.config.ENUM_BZ_RESPONSE_RESULT;
import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("BatchTransRes")
public class ResponseBase {
	/**返回报文头*/
	private ResponseHead BatchTransHead;
	/**返回报文体*/
	private ResultInfo ResultInfo;

	
	public ResponseHead getBatchTransHead() {
		return BatchTransHead;
	}

	public void setBatchTransHead(ResponseHead batchTransHead) {
		BatchTransHead = batchTransHead;
	}

	public ResultInfo getResultInfo() {
		return ResultInfo;
	}

	public void setResultInfo(ResultInfo resultInfo) {
		ResultInfo = resultInfo;
	}
	
	 /**
     * 报文响应成功
     *
     * @Title: success
     * @Description: 报文响应成功
     */
    public void success() {
        checkInitHead();
        this.getBatchTransHead().setResultCode(ENUM_BZ_RESPONSE_RESULT.SUCCESS.code());
        this.getBatchTransHead().setResultMsg(ENUM_BZ_RESPONSE_RESULT.SUCCESS.description());
    }

    /**
     * 检查报文头是否为空
     *
     * @Title: checkInitHead
     * @Description: 检查报文头是否为空
     */
    private void checkInitHead() {
        // TODO Auto-generated method stub
        ResponseHead head = this.getBatchTransHead();
        if (head == null) {
            head = new ResponseHead();
            head.setMerchantCode("");
            head.setSerialNo("");
            head.setResultMsg("");
            head.setPayRequestDate("");
            head.setSign("");
            head.setResultCode("");
            this.setBatchTransHead(head);
        }
    }

    /**
     * 设置报文体内容
     *
     * @param obj
     * @Title: setResponseBody
     * @Description: 设置报文体内容 将封装好的报文体set到子类的报文体属性中即可
     */
    //public abstract void setResponseBody(Object obj);

    /**
     * 报文响应异常
     *
     * @param message
     * @Title: exception
     * @Description: TODO
     */
    public void exception(String message) {
        checkInitHead();
        this.getBatchTransHead().setResultCode(ENUM_BZ_RESPONSE_RESULT.EXCEPTION.code());
        if (StringUtil.isNotBlank(message))
            this.getBatchTransHead().setResultMsg(message);
        else
            this.getBatchTransHead().setResultMsg(ENUM_BZ_RESPONSE_RESULT.EXCEPTION.description());
    }

    /**
     * 报文响应错误
     *
     * @param message
     * @Title: exception
     * @Description: 报文响应错误调用方法
     */
    public void failture(String message) {
        checkInitHead();
        this.getBatchTransHead().setResultCode(ENUM_BZ_RESPONSE_RESULT.FAIL.code());
        if (StringUtil.isNotBlank(message))
            this.getBatchTransHead().setResultMsg(message);
        else
            this.getBatchTransHead().setResultMsg(ENUM_BZ_RESPONSE_RESULT.FAIL.description());
    }

}
